package com.newhero.product.common.mybatis.plugins.pagination.dialects;

import com.newhero.product.common.mybatis.plugins.pagination.IDialect;

public class OscarDialect implements IDialect{

	public static final OscarDialect INSTANCE = new OscarDialect();
	
	public String buildPaginationSql(String originalSql, int offset, int limit) {
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT * FROM ( SELECT TMP.*, ROWNUM ROW_ID FROM ( ");
		sql.append(originalSql).append(" ) TMP WHERE ROWNUM <=").append((offset >= 1) ? (offset + limit) : limit);
		sql.append(") WHERE ROW_ID > ").append(offset);
		return sql.toString();
	}
}
